package com.leyou.controller;

import com.leyou.dto.SkuDTO;
import com.leyou.dto.SpuDTO;
import com.leyou.pojo.Sku;
import com.leyou.pojo.Spu;
import com.leyou.service.SkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author jshstart
 * @creat 2020-12-11 22:03
 */

@RestController
@RequestMapping("/goods")
public class SkuController {
    @Autowired
    private SkuService skuService;
    @GetMapping("/sku/list")
    public ResponseEntity<List<SkuDTO>> querySopuByIds(@RequestParam("ids") List<Long> ids){
        List<Sku> skuList = skuService.listByIds(ids);
        List<SkuDTO> dtoList = skuList.stream().map(SkuDTO::new).collect(Collectors.toList());
        return ResponseEntity.ok(dtoList);
    }
    @GetMapping("/sku/of/spu")
    public ResponseEntity<List<SkuDTO>> querySopuBySpuId(@RequestParam("id") Long id){
        List<Sku> skuList = skuService.query().eq("spu_id", id).list();
        List<SkuDTO> dtoList = skuList.stream().map(SkuDTO::new).collect(Collectors.toList());
        return ResponseEntity.ok(dtoList);
    }
}
